#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
//https://www.luogu.com.cn/problem/P1208
using namespace std;

const int N = 1e6 + 10;
typedef pair<int, int> PII;
PII a[N];

int n, m;
int res;
void fun()
{
	while (n > 0)
	{
		for (int i = 1 ; i <= m ; ++i)
		{
			auto t = a[i];
			while (t.second--)
			{
				res+=t.first;
				n--;
				if (n == 0)
					return;
			}
		}
	}
}

int main()
{

	cin >> n >> m;

	for (int i = 1; i <= m; ++i)
	{
		cin >> a[i].first >> a[i].second;
	}

	sort(a + 1, a + 1 + m, less<PII>());

	//for (int i = 1; i <= m; ++i)
	//{
	//	cout <<a[i].first << a[i].second <<endl;
	//}
	fun();
	cout << res << endl;


	return 0;
}